﻿$("#btnlogin").click(function () {
    UserLogin();
})

function SetUserDefaultVal() {
    var username = "";
    var pwd = "";

    if ($.cookie("rmbUser") == "true") {
        username = $.cookie("account");
        pwd = $.cookie("password");
    }
    $("#txtUserName").val(username);
    var opart = new jsonRow();

    opart = addStatistics(opart, "首页", "w0003", "", "", "");
    opart.AddCell("ACTION", "init");

    if (!IsNull(username)) {
        opart.AddCell("password", pwd);
    } else {
        opart.AddCell("password", "");
    }
    ajaxComm(opart, null, null, null, null);
}

$(function () {
    SetUserDefaultVal();
})

function UserLogin() {
    var userName = $.trim($("#txtUserName").val());
    if (IsNull(userName)) {
        ShowErrMsg("用户名不能为空");
        return;
    }

    //if (!IsEmail(userName)) {
    //    ShowErrMsg("用户名只能是邮箱");
    //    return;
    //}

    var password = $.trim($("#pwdPassword").val());
    if (IsNull(password)) {
        ShowErrMsg("密码不能为空");
        return;
    }

    if (!islength(password, 6, 16)) {
        ShowErrMsg("密码长度只能为6-16位之间");
        return;
    }

    //var isRemember = $("#chkRember").attr("checked") == "checked";

    var _jsParam = new jsonRow();
    _jsParam.AddCell("account", userName);
    _jsParam.AddCell("password", password);
    //_jsParam.AddCell("isRemember", isRemember);
    _jsParam.AddCell("ACTION", "login");
    ajaxComm(_jsParam);
}


//登录成功，页面跳转
function susccLogin() {
    window.location.href = "/wp_index.htm";
}

//保存cookie
function setCookie(account, pwd) {
    if ($("#chkRember").prop("checked")) {//判断是否要记住密码
        $.cookie("rmbUser", "true", { expires: 10 });
        $.cookie("account", account, { expires: 10 });
        $.cookie("password", pwd, { expires: 10 });
    } else {
        $.cookie("rmbUser", "false", { expires: -1 });
        $.cookie("account", "", { expires: -1 });
        $.cookie("password", "", { expires: -1 });
    }
}

function ShowErrMsg(msg) {
    $(".login_notice").show();
    $(".login_notice").text(msg);
}

function ShowVehicle(strJson) {
    var _html = $('#vehicle_list_temp').html();
    laytpl(_html).render(strJson, function (render) {
        $('#butique-vehicle-content').html(render);

    });
}

function ShowRecomm(strJson) {
    var _html = $('#recomm_list_temp').html();
    laytpl(_html).render(strJson, function (render) {
        $('#butique-recomm-content').html(render);
    });
}


function ChangeShowImgInfo() {
    var windW = $(window).width();
    if (windW <= 1435) {
        $(".scrollPic").css("left", (windW - 1435) / 2);

        var oldLeft = $(".leader-login-wrap").css("left").split('p')[0];
        var newLeft = oldLeft - (1435 - windW) / 2;
        newLeft = newLeft < 900 ? 900 : newLeft;

        $(".leader-login-wrap").css("left", newLeft + "px");
    }
}
ChangeShowImgInfo();

$(window).resize(function () {
    window.location.href = "/";
})

function TurnScrollPic() {
    var frtCld = $(".scrollPic").children("li").eq(0);
    var lft = $(".scrollPic").css("left");
    $(".scrollPic").stop(true, true).animate({ left: '-=' + 1435 + 'px' }, "slow", function () {
        $(this).css("left", lft).append(frtCld);
    });
}

var interval = setInterval(TurnScrollPic, 5000);

$(function () {
    $(".scrollPic").hover(function () {
        clearInterval(interval);
    }, function () {
        interval = setInterval(TurnScrollPic, 5000);
    })
})

$(function () {
    $(".cancel-abs").click(function () {
        $(".footer-abs").slideUp("slow", function () {
            $(this).hide();
        })
    })
})